﻿using System;
using System.Collections.Generic;

namespace WingbotDriver
{
    class Program
    {
        static readonly Dictionary<string, WingBot.TeamPosition> PositionDict = new()
        {
            { "Front", WingBot.TeamPosition.FRONT },
            { "Back", WingBot.TeamPosition.BACK },
            { "front", WingBot.TeamPosition.FRONT },
            { "back", WingBot.TeamPosition.BACK },
            { "Master", WingBot.TeamPosition.FRONT },
            { "Slave", WingBot.TeamPosition.BACK },
            { "master", WingBot.TeamPosition.FRONT },
            { "slave", WingBot.TeamPosition.BACK },
            { "test", WingBot.TeamPosition.UNKOWN }
        };

        /// <summary>
        /// dotnet run "Master" 192.168.4.11 5000
        /// </summary>
        /// <param name="args">是主车还是从车，Stm32的IP</param>
        static void Main(string[] args)
        {
            var robot = new WingBot();
            var slave = new WingBot();

            robot.TeamRole = WingBot.TeamPosition.FRONT;
            robot.LowLayerPort = 5000;
            robot.LowLayerIp = "192.168.31.23";

            if (args.Length == 1)
            {
                robot.TeamRole = PositionDict[args[0]];
            }
            else if (args.Length == 3)
            {
                robot.TeamRole = PositionDict[args[0]];
                robot.LowLayerIp = args[1];
                robot.LowLayerPort = Convert.ToInt32(args[2]);
            }

            if (robot.TeamRole == WingBot.TeamPosition.FRONT)
            {
                slave.TeamRole = WingBot.TeamPosition.BACK;
                slave.LowLayerIp = "192.168.31.21";
                slave.LowLayerPort = 5000;
                robot.BindSlave(slave);
            }

            robot.battery.Begin();
            robot.BeginListen();
            if (robot.TeamRole != WingBot.TeamPosition.UNKOWN)
                robot.Begin();
            robot.Loop();
        }
    }
}
